﻿using System;
using System.Net;
using System.Net.Sockets;

namespace MyMailWp8.Protocol
{
    enum PESocketErrCode
    {
        NOT_CONNECT = 20000,
        SEND_BUFFER_ERR = 20001,
        IP_ADDRESS_ERR = 20002
    };

    public class PESocketException : Exception
    {
        private int _socketErrCode;

        public PESocketException()
            :base()
        {

        }
        public override string Message 
        { 
            get
            {
                string ret = "未知网络错误";
                switch (_socketErrCode)
                {
                    case (int)SocketError.AccessDenied:
                        ret = "没有网络访问权限。";
                        break;
                    case (int)SocketError.ConnectionAborted:
                        ret = "网络访连接中断。";
                        break;
                    case (int)SocketError.ConnectionReset:
                        ret = "服务器中断连接。";
                        break;
                    case (int)SocketError.TooManyOpenSockets:
                        ret = "连接到达上限。";
                        break;
                    case (int)SocketError.NetworkDown:
                        ret = "无法连接网络。";
                        break;
                    case (int)SocketError.TimedOut:
                        ret = "连接超时。";
                        break;
                    case (int)SocketError.Shutdown:
                        ret = "连接已经被关闭。";
                        break;
                    case (int)SocketError.SystemNotReady:
                        ret = "系统不支持网络操作。";
                        break;
                    case (int)PESocketErrCode.NOT_CONNECT:
                        ret = "没有建立网络连接；或连接出错。";
                        break;
                    case (int)PESocketErrCode.SEND_BUFFER_ERR:
                        ret = "发送缓冲区为空。";
                        break;
                    case (int)PESocketErrCode.IP_ADDRESS_ERR:
                        ret = "服务器地址错误。";
                        break;
                    default:
                        break;
                }
                return ret;
            }
        }

        public int ErrCode
        {
            get
            {
                return (int)_socketErrCode;
            }
        }

        public PESocketException(int SocketErrCode)
            : base()
        {
            _socketErrCode = SocketErrCode;
        }

        public override string ToString()
        {
            return Message;
        } 


    }
}
